
var express = require('express');
var router = express.Router();
var moment = require('moment');
var {parklotsModel}=require("../utils/model")
router.get("/",function(req,res){
    res.send("<script>alert('car')</script>")
})

router.get("/parklot",function(req,res){
    parklotsModel.find().then(data=>{
console.log(data);
        res.render('parklot',{
            title:'parklot',
            username:"a",
            data,
        })
    }).catch(err=>{
        res.send("<script>alert('查询异常！')</script>")
    })
})

// 删除一条

router.get('/delOne',(req,res)=>{
    console.log(req.query);
    parklotsModel.deleteOne(req.query)
    .then(function(){
        res.send("<script>alert('删除成功！');location.href='http://localhost:3000/car/parklot'</script>");
    }).catch(err=>{
        res.send("<script>alert('删除出错！');location.href='http://localhost:3000/car/parklot'</script>");
    })
    ;
    
})
module.exports = router;
